package com.shiguo365.market.presenter.implement;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.shiguo365.market.display.view.ICartView;
import com.shiguo365.market.presenter.contract.ICartPresenter;

import java.util.List;

import biz.yfsoft.app.aengine.api.AEClient;
import biz.yfsoft.app.aengine.api.AEParam;
import biz.yfsoft.app.aengine.api.BaseAECallback;

/**
 * Created by CoderA on 2016/7/10.
 */
public class CartPresenter implements ICartPresenter {

    private static final String TAG = "CartPresenter";
    private final Activity mActivity;
    private final ICartView mCartView;

    public CartPresenter(@NonNull Activity activity, @NonNull ICartView cartView) {
        this.mActivity = activity;
        this.mCartView = cartView;
    }

    @Override
    public void getCartById(Integer uid) {
        AEClient _client = new AEClient("shiguo.cart.getByUid");
        _client.call(new AEParam().set("uid",uid),new BaseAECallback() {
            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(List<JSONObject> list) {
                mCartView.onGetCartOk(list);
            }

            @Override
            public void onError( String errno, String message) {
                Log.e(TAG,"onFailure ......." + errno);
            }

            @Override
            public void onFinally() {
                mCartView.onGetCartFinished();
            }
        });
    }
}
